﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aphysoft.Vate.Graphics
{
    internal sealed class CameraDebugger : IDebugCommandHandler
    {
        #region Constructor

        internal CameraDebugger()
        {
            Debug.RegisterCommandHandler("camera", this);
        }

        #endregion

        #region IDebugCommandHandler Members
        /// <summary>
        /// Internal use only.
        /// </summary>
        public bool Call(string command, string parameter)
        {
            if (command == "camera")
            {
                #region help
                if (parameter.ToLower() == "help")
                {
                    Debug.Write("Camera Manager");
                    Debug.Write("list - lists all camera in this manager");
                    Debug.Write("info <camera name> - get camera position, up, target vector");
                }
                #endregion
                #region lists cameras in this manager: camera list
                else if (parameter.ToLower() == "list")
                {
                    Debug.Write(StringHelper.Create("Camera available: ", CameraManager.Cameras.Count));
                    int i = 0;
                    foreach (KeyValuePair<string, Camera> entry in CameraManager.Cameras)
                    {
                        i++;
                        Debug.Write(StringHelper.Create(i, ". ", entry.Key));
                    }
                }
                #endregion
                #region show location specified camera: camera position <cameraname>
                else if (parameter.ToLower().StartsWith("info "))
                {
                    string actcn = parameter.Substring(5).Trim();

                    if (CameraManager.Cameras.ContainsKey(actcn))
                    {
                        Debug.Write(StringHelper.Create("Position: ", CameraManager.Cameras[actcn].Position));
                        Debug.Write(StringHelper.Create(" Forward: ", CameraManager.Cameras[actcn].Forward));
                        Debug.Write(StringHelper.Create("      Up: ", CameraManager.Cameras[actcn].Up));
                        Debug.Write(StringHelper.Create("   Right: ", CameraManager.Cameras[actcn].Right));
                        Debug.Write(StringHelper.Create("  Target: ", CameraManager.Cameras[actcn].CameraTarget));
                    }
                    else
                        Debug.Write(StringHelper.Create("Camera \"", actcn, "\" not found."));
                }
                #endregion
                else
                {
                    Debug.Write("Camera Manager, see camera help for more information.");
                }
                return true;
            }

            return false;
        }
        /// <summary>
        /// Internal use only.
        /// </summary>
        public string Description(string command)
        {
            if (command == "camera")
            {
                return "Camera manager";
            }

            return null;
        }
        #endregion
    }
}
